package com.gnerv.plug.maven;

import com.gnerv.plug.maven.action.DependencyVersionAction;
import com.gnerv.plug.maven.model.DependencyInfo;
import com.intellij.openapi.actionSystem.ActionGroup;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;


public class DependencyGroupAction extends ActionGroup {

    private DependencyInfo dependencyInfo;

    public DependencyGroupAction() {
    }

    public DependencyGroupAction(@Nullable String shortName, boolean popup) {
        super(shortName, popup);
    }

    public DependencyGroupAction(@Nullable String shortName, boolean popup, DependencyInfo dependencyInfo) {
        super(shortName, popup);
        this.dependencyInfo = dependencyInfo;
    }

    @NotNull
    @Override
    public AnAction[] getChildren(AnActionEvent e) {
        AnAction[] anActions = new AnAction[dependencyInfo.getVersions().size()];
        for (int i = 0; i < dependencyInfo.getVersions().size(); i++) {
            Map<String, String> dependency = new HashMap<>();
            dependency.put("groupId", dependencyInfo.getGroupId());
            dependency.put("artifactId", dependencyInfo.getArtifactId());
            dependency.put("version", dependencyInfo.getVersions().get(i));
            anActions[i] = new DependencyVersionAction(dependency, null);
        }
        return anActions;
    }
}
